﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LogicExpressionCalculator;

namespace FeatureModelTest
{
    [TestClass]
    public class TestLogicCalculator
    {
        [TestMethod]
        public void TestLogicExpressionCalculate()
        {
            Stack<object> expression = new Stack<object>();
            // ^VT^!TF V =>TF ->FT 
            // result: T
            expression.Push(LogicOperatorType.Conjunction);
            expression.Push(LogicOperatorType.Disjunction);
            expression.Push(true);
            expression.Push(LogicOperatorType.Conjunction);
            expression.Push(LogicOperatorType.Negation);
            expression.Push(true);
            expression.Push(false);
            expression.Push(LogicOperatorType.Disjunction);
            expression.Push(LogicOperatorType.Biconditional);
            expression.Push(true);
            expression.Push(false);
            expression.Push(LogicOperatorType.Implication);
            expression.Push(false);
            expression.Push(true);

            Assert.IsTrue(ExpressionCalculator.LogicCalculate(expression));
        }
        [TestMethod]
        public void TestLogicExpressionGetResultSet()
        {
            LogicExpression express = new LogicExpression();
            // (A => B) V C
            // V=>ABC
            LogicOperand A = express.GenerateOperand("A");
            LogicOperand B = express.GenerateOperand("B");
            LogicOperand C = express.GenerateOperand("C");
            express.Add(LogicOperator.Disjunction);
            express.Add(LogicOperator.Biconditional);
            express.Add(A);
            express.Add(B);
            express.Add(C);
            List<string[]> retList = express.CalculateLogicSatisfy();
            // C is true or A and B are true at same time.
            foreach (string[] strList in retList)
            {
                foreach (string str in strList)
                {
                    Console.Write("{0},", str);
                }
                Console.WriteLine();
            }

            // (B=>(!C^!D^A)) ^(C=>(!B^!D^A)) ^(D=>(!B^!C^A))
            // ^^=>B^^A!C!D=>B^^A!B!D=>D^^A!B!C
            express = new LogicExpression();
            A = express.GenerateOperand("A");
            B = express.GenerateOperand("B");
            C = express.GenerateOperand("C");
            LogicOperand D = express.GenerateOperand("D");

            express.Add(LogicOperator.Conjunction);
            express.Add(LogicOperator.Conjunction);

            express.Add(LogicOperator.Biconditional);
            express.Add(B);
            express.Add(LogicOperator.Conjunction);
            express.Add(LogicOperator.Conjunction);
            express.Add(A);
            express.Add(LogicOperator.Negation);
            express.Add(C);
            express.Add(LogicOperator.Negation);
            express.Add(D);

            express.Add(LogicOperator.Biconditional);
            express.Add(C);
            express.Add(LogicOperator.Conjunction);
            express.Add(LogicOperator.Conjunction);
            express.Add(A);
            express.Add(LogicOperator.Negation);
            express.Add(B);
            express.Add(LogicOperator.Negation);
            express.Add(D);

            express.Add(LogicOperator.Biconditional);
            express.Add(D);
            express.Add(LogicOperator.Conjunction);
            express.Add(LogicOperator.Conjunction);
            express.Add(A);
            express.Add(LogicOperator.Negation);
            express.Add(C);
            express.Add(LogicOperator.Negation);
            express.Add(B);

            retList = express.CalculateLogicSatisfy();
        }
    }
}
